home *** CD-ROM | disk | FTP | other *** search
/ SPACE 2 / SPACE - Library 2 - Volume 1.iso / apps / 25 / applic / rgen.pas < prev    next >
Encoding:
Pascal/Delphi Source File  |  1986-06-19  |  5.3 KB  |  270 lines

  1. (*
  2.     RLEGEN, Translate DEGAS .PI1 file into a .RLE file
  3.  
  4.     FUNCTION:
  5.  
  6.     RLEGEN takes a DEGAS low resolution (.PI1) file and encodes it
  7.     in the CompuServe .RLE format.
  8.  
  9.     USAGE:
  10.  
  11.     When you run this program you will be prompted for the names
  12.     of two files, the input .PI1 file and the output .RLE file.
  13.     Conversion will then take place.
  14.  
  15.     NOTES:
  16.  
  17.     RLE Format files are 256 wide by 192 deep, with each pixel
  18.     being either black or white.  DEGAS .PI1 files are 320 wide
  19.     by 200 deep, with each pixel having 4 bits of color information.
  20.  
  21.     As you might guess, there is quite a bit of information lost when
  22.     encoding a .PI1 into a .RLE file; 64 columns, 8 rows, and 3 bits
  23.     of color depth.  Pretty grim.
  24.  
  25.     This program will encode a subset of the entire DEGAS image
  26.     occupying the upper left hand corner of the image.  All pixels
  27.     which are not black are considered full white.  This conversion
  28.     works poorly for images which are shaded.  A better version
  29.     of this program will come in the future...
  30.  
  31.     AUTHOR:
  32.  
  33.     Charles McGuinness, May 1986
  34.  
  35.     MODIFICATIONS:
  36.  
  37.     <your name goes here ... don't forget to describe what you did>
  38.  
  39. *)
  40.  
  41. program rlegen;
  42.  
  43. type    t_image = array [0..15999] of integer;
  44.     t_outf = packed file of byte;
  45.  
  46. var    image            : ^t_image;
  47.  
  48.     inf            : file of integer;
  49.     outf            : t_outf;
  50.  
  51.     map            : array [0..15] of boolean;
  52.         
  53.     d_type            : integer;
  54.  
  55.     x,y,i,j,k        : integer;
  56.  
  57.     black,white,state    : integer;
  58.  
  59.     line            : string;
  60.  
  61. procedure io_check(b:boolean); external;
  62. function io_result:integer; external;
  63.  
  64. procedure my_halt;
  65. begin
  66.     write('Press RETURN to continue: ');
  67.     readln;
  68.     halt;
  69. end;
  70.  
  71. (*
  72.     get_pix, Get the value of a pixel in the DEGAS image
  73.  
  74.     This routine will return TRUE if the specified pixel is WHITE,
  75.     FALSE if the pixel is BLACK.  Does full magic to map colors
  76.     through the color map.
  77.  
  78. *)
  79.  
  80. function get_pix(x,y:integer):boolean;
  81. var    offset,    bit, normal, color : integer;
  82. begin
  83.  
  84.  
  85.     offset    := y * 80 + (x div 16)*4;
  86.  
  87.     bit    := shr($8000,x & 15);    (* The Bit mask            *)
  88.     normal    := 15 - (x & 15);    (* # shifts to normalize    *)
  89.  
  90.     color    := shl(shr(image^[offset+0] & bit,normal),0) |
  91.            shl(shr(image^[offset+1] & bit,normal),1) |
  92.            shl(shr(image^[offset+2] & bit,normal),2) |
  93.            shl(shr(image^[offset+3] & bit,normal),3);
  94.  
  95.     get_pix := map[color];
  96. end;
  97.  
  98. (*    putc, for us C programmers who have a hard time changing to pascal *)
  99. procedure putc(c:integer;var f:t_outf);
  100. begin
  101.     f^ := c;
  102.     put(f);
  103. end;
  104.  
  105. BEGIN        (* MAIN *)
  106.  
  107. writeln('DEGAS to RLE Conversion utility, version 1.0 (May 28, 1986)');
  108. writeln;
  109. writeln('Copyright (C) 1986, Charles McGuinness');
  110. writeln;
  111. writeln('Portions if this product are Copyright (c) 1986, OSS and CCD.');
  112. writeln('Used by Permission of OSS.');
  113. writeln;
  114. writeln;
  115.  
  116.     new(image);
  117.  
  118.     write('Input (.PI1) filename:  ');
  119.     readln(line);
  120.     io_check(FALSE);
  121.     reset(inf,line);
  122.     if (io_result <> 0) then begin
  123.         writeln('Unable to open ',line);
  124.         my_halt;
  125.         end;
  126.  
  127.     io_check(TRUE);
  128.     write('Output (.RLE) filename: ');
  129.     readln(line);
  130.     io_check(FALSE);
  131.     rewrite(outf,line);
  132.     if (io_result <> 0) then begin
  133.         writeln('Unabe to create ',line);
  134.         my_halt;
  135.         end;
  136.  
  137.     io_check(TRUE);
  138.  
  139.     writeln;
  140.  
  141. (*    1: Read in file type                        *)
  142.  
  143.     d_type := inf^;        get(inf);
  144.  
  145.     if (d_type <> 0) then begin
  146.         write('File is not DEGAS low resolution.  Press return:');
  147.         close(inf);
  148.         close(outf);
  149.         halt;
  150.         end;
  151.  
  152. (*    2: Read color map                        *)
  153.  
  154.     for i:= 0 to 15 do begin
  155.         d_type    := inf^;
  156.         get(inf);
  157.         map[i] := (d_type & $777) <> 0;
  158.         end;
  159.  
  160.  
  161. (*    3: Read in image                        *)
  162.  
  163.     writeln('Reading DEGAS image in....');
  164.     writeln;
  165.     write('<    0>');
  166.     for i:=0 to 15999 do begin
  167.         image^[i] := inf^;
  168.         get(inf);
  169.         if ((i mod 80) = 39) then
  170.             write('.');
  171.         if ((i mod (80*64)) = (80*64)-1) then begin
  172.             writeln;
  173.             write('<',((i+1) div 80):5,'>');
  174.             end;
  175.         end;
  176.  
  177.     writeln; writeln;
  178.  
  179.     close(inf);
  180.  
  181.  
  182.     writeln('Generating .RLE file ...');
  183.     writeln;
  184.     write('<    0>');
  185.     putc(27,outf);
  186.     putc(ord('G'),outf);
  187.     putc(ord('H'),outf);
  188.  
  189. (*    4: Convert!                            *)
  190.  
  191.     white    := 0;
  192.     black    := 0;
  193.     state    := 1;
  194.  
  195.     for y := 0 to 191 do begin
  196.  
  197.     write('.');
  198.     if ((y mod 64) = 63) then begin
  199.         writeln;
  200.         write('<',(y+1):5,'>')
  201.         end;
  202.  
  203.     for x := 0 to 255 do
  204.  
  205.     case (state) of
  206.  
  207.     0:                 (* White            *)
  208.  
  209.         if (get_pix(x,y)) then begin    (* Still white...    *)
  210.             white := succ(white);
  211.             if (white = 94) then begin
  212.                 putc(white+32,outf);
  213.                 putc(32,outf);
  214.                 white := 0;
  215.                 end;
  216.             end
  217.         else begin
  218.             putc(white+32,outf);
  219.             black := 1;
  220.             white := 0;
  221.             state := 1;
  222.             end;
  223.  
  224.  
  225.     1:                (* Black            *)
  226.  
  227.         if (not get_pix(x,y)) then begin
  228.                     (*    Still black        *)
  229.             black := succ(black);
  230.             if (black = 94) then begin
  231.                 putc(black+32,outf);
  232.                 putc(32,outf);
  233.                 black := 0;
  234.                 end;
  235.             end
  236.         else begin
  237.             putc(black+32,outf);
  238.             white := 1;
  239.             black := 0;
  240.             state := 0;
  241.             end;
  242.         end (* case *);
  243.  
  244.     end; (* for y *)
  245.  
  246.     case (state) of
  247.  
  248.     0:    begin                (* White        *)
  249.         putc(white+32,outf);
  250.         putc(32,outf);
  251.         end;
  252.  
  253.     1:                    (* Black        *)
  254.         putc(black+32,outf);
  255.     end;
  256.  
  257.             
  258.  
  259.     putc(27,outf);                (* Escape        *)
  260.     putc(ord('G'),outf);
  261.     putc(ord('N'),outf);
  262.  
  263.     close(outf);
  264.  
  265.     writeln;
  266.     writeln;
  267.     writeln('DEGAS to RLE conversion finished.');
  268.     my_halt;
  269. end.
  270. əəəəəəəəəəəəəəəəəəəəəəəə